package com.tau.egonetwork.excel;

import com.tau.egonetwork.linkedin.LinkedinFollowProfile;
import com.tau.egonetwork.linkedin.LinkedinMainProfile;
import com.tau.egonetwork.linkedin.LinkedinUtils;
import com.tau.egonetwork.profiles.Group;
import com.tau.egonetwork.profiles.MainProfile;
import com.tau.egonetwork.profiles.Profile;

class LinkedinExcel implements IExcel {

	@Override
	public MainProfile<?> createMainProfile(String name) {
		return new LinkedinMainProfile(LinkedinUtils.generateRandomID(), name);
	}

	@Override
	public Profile<?> createProfile(String name) {
		return new LinkedinFollowProfile(LinkedinUtils.generateRandomID(), name);
	}

	@Override
	public void addToFriendsList(MainProfile<?> main, Profile<?> friend) {
		LinkedinMainProfile profile = (LinkedinMainProfile)main;
		LinkedinFollowProfile friendProfile = (LinkedinFollowProfile)friend;
		profile.getFriendsList().add(friendProfile);		
	}

	@Override
	public void createConnection(Profile<?> p1, Profile<?> p2) {
		//cast specifically:
		LinkedinFollowProfile f1 = (LinkedinFollowProfile)p1;
		LinkedinFollowProfile f2 = (LinkedinFollowProfile)p2;
		
		//create if not exists:
		if (f1.getFriendsList() == null)
			f1.createFriendsList();
		if (f2.getFriendsList() == null)
			f2.createFriendsList();
		
		//create said connection:
		f1.getFriendsList().add(f2);
		f2.getFriendsList().add(f1);

	}

	@Override
	public Group<?> createGroup(String name) {
		return new Group<String>(name);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void addToGroup(Group<?> group, Profile<?> profile) {
		Group<String> g = (Group<String>)group;
		LinkedinFollowProfile p = (LinkedinFollowProfile)profile;
		g.add(p);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void addGroup(Group<?> group, MainProfile<?> mainProfile) {
		LinkedinMainProfile p = (LinkedinMainProfile)mainProfile;
		Group<String> g = (Group<String>)group;
		p.getGroupsList().add(g);
	}

}
